#include "datarecord_menu.h"

dataRecord_Menu::dataRecord_Menu(QWidget *parent) : QMainWindow(parent)
{
    this->setStyleSheet("QMainWindow{background-image: url(:/pic/背景板.png);}");
    this->setFixedSize(640,430);
    ui_Init();
    connect_Init();
}
void dataRecord_Menu::ui_Init()
{

    for(int i=0;i<3;i++)//创建主屏幕显示的按键
    {
         theLabel[i] = new QLabel(this);
    }
    theLabel[0]->setStyleSheet("QLabel{ image: url(:/pic/logo.png); background-color: rgb(20, 170, 225);}"    );
    theLabel[0]->setStyleSheet("QLabel{"
                          + the_StyleSheet[20]+ " font-size: 25px;"+ "background-color: rgb(20, 70, 255);	    /* 背景颜色 */"+  "}"    );
    theLabel[1]->setStyleSheet("QLabel{ image: url(:/pic/左.png); }"    );
    theLabel[2]->setStyleSheet("QLabel{ image: url(:/pic/右.png); }"    );

   theLabel[0]->setGeometry(0,0,640,60);//设定每隔放置一个按键
   theLabel[1]->setGeometry(0,0,300,60);//设定每隔放置一个按键
   theLabel[2]->setGeometry(340,0,300,60);//设定每隔放置一个按键
   theLabel[0]->setText("数据记录");


    for(int i=0;i<3;i++)//创建主屏幕显示的按键
    {
         theBtn[i] = new QPushButton(this);
//        newbutton->setGeometry(30+(i*150),260,120,90 );//设定每隔放置一个按键
        theBtn[i]->setFixedSize(120,90);
        theBtn[i]->geometry();
        theBtn[i]->setStyleSheet("QPushButton{\
                               outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
                               background-color: rgb(0, 170, 255);	    /* 背景颜色 */\
                               border-radius: 6px;		                 /* 按钮边框的圆角设置 */\
                               border-style: outset;\
                               /* 按钮背景图标设置 */\
                               background-image: url(:/pic/access/气象站.png); /* 背景图片 */\
                               background-origin: content;\
                               background-position: top;	         /* 背景图片的位置 */\
                               padding-right: 0px;	    /*内边距设置*/	    \
                               padding-left: 0px;		/*  */	\
                               padding-bottom: 10px;		/*  */    \
                               padding-top: 10px;		/*  */    \
                               background-repeat: no-repeat;	         /* 设置背景图像的平铺模式 */\
                               /* 按钮文本设置 */\
                               text-align: bottom;			             /* 文本的位置 */\
                               font-size: 20px;\
                               color: #FFFFFF;			                 /* 文本颜色 */\
                          }"
    "QPushButton:focus{\
outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
    background-color: rgb(255,125,25);	    /* 背景颜色 */\
    border-radius: 6px;		                 /* 按钮边框的圆角设置 */\
    border-style: outset;\
    /* 按钮背景图标设置 */\
    background-image: url(:/pic/access/过滤.png); /* 背景图片 */\
    background-origin: content;\
    background-position: top;	         /* 背景图片的位置 */\
    padding-right: 0px;	    /*内边距设置*/	    \
    padding-left: 0px;		/*  */	\
    padding-bottom: 10px;	/*  */   \
    padding-top: 10px;		/*  */    \
    background-repeat: no-repeat;	         /* 设置背景图像的平铺模式 */\
    /* 按钮文本设置 */\
    text-align: bottom;			             /* 文本的位置 */\
    font-size: 22px;\
    qproperty-iconSize: 20px 20px;			/* 设置图标大小*/\
color: rgb(125, 255, 250);			                 /* 文本颜色 */\
}"
"QPushButton:pressed{background-color:rgb(99,211,133);}"
"QPushButton:checked{background-color:rgb(66,66,99);}"
//"QPushButton:hover{background-color:rgb(255,111,111);}"
//"QPushButton:MouseButtonPress{background-color:rgb(255,111,111);}"
    );

//        newbutton->setIconSize(QSize(1,2));
btnlist_ui.append(theBtn[i]);

}

theBtn[0]->setStyleSheet(  "QPushButton{"+the_StyleSheet[0]+"color: rgb(255,125,25);	  /* 文本颜色 */"+"background-color: rgb(170, 10, 15);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/O3/传递标准.png); /* 背景图片 */"+"}"
 "QPushButton:focus{"+the_StyleSheet[1]+"color: rgb(255,125,25);	  /* 文本颜色 */"+"background-color: rgb(170, 10, 15);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/O3/传递标准2.png); /* 背景图片 */"+"}");
theBtn[1]->setStyleSheet(  "QPushButton{"+the_StyleSheet[0]+"color: rgb(255,125,25);	  /* 文本颜色 */"+"background-color: rgb(230, 210, 155);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/O3/光度计控制.png); /* 背景图片 */"+"}"
 "QPushButton:focus{"+the_StyleSheet[1]+"color: rgb(255,125,25);	  /* 文本颜色 */"+"background-color: rgb(230, 210, 155);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/O3/光度计控制2.png); /* 背景图片 */"+"}");
theBtn[2]->setStyleSheet(  "QPushButton{"+the_StyleSheet[0]+"color: rgb(255,125,25);	  /* 文本颜色 */"+"background-color: rgb(60, 255, 152);	    /* 背景颜色 */ ;"+ "background-image: url(:/pic/返回.png); /* 背景图片 */"+"}"
 "QPushButton:focus{"+the_StyleSheet[1]+"background-color: rgb(60, 255, 152);	    /* 背景颜色 */ ;"+"color: rgb(255,125,25);	  /* 文本颜色 */"+ "background-image: url(:/pic/Airflow_mode/返回2.png); /* 背景图片 */"+"}");

btnlist_ui.at(0)->setText(tr("查看数据"));
btnlist_ui.at(1)->setText(tr("清除记录"));
btnlist_ui.at(2)->setText(tr("返回"));

QGridLayout *theLayout = new QGridLayout();
theLayout->addWidget(btnlist_ui.at(0), 1, 0);
theLayout->addWidget(btnlist_ui.at(1), 1, 1);
theLayout->addWidget(btnlist_ui.at(2), 1, 2);

//theLayout->setVerticalSpacing(50);
//theLayout->setHorizontalSpacing(10);
theLayout->setContentsMargins(0,120,0,0);//(int left, int top, int right, int bottom)
//theLayout->setColumnStretch(1,22);
theLayout->setSizeConstraint(QLayout::SetMinimumSize);
  setLayout(theLayout);

  QWidget* widget = new QWidget(this);
  widget->setGeometry(0,0,640,330);
  widget->setLayout(theLayout);

//事件过滤器
foreach (QPushButton *btn, btnlist_ui) {
    btn->installEventFilter(this);
}
}
void dataRecord_Menu::connect_Init()
{
    //查看记录
    connect(btnlist_ui.at(0),&QPushButton::clicked,[=](){
                lookRecord_Date  *menux = new lookRecord_Date(this);
                menux->show();

    });

    //清理记录
    connect(btnlist_ui.at(1),&QPushButton::clicked,[=](){
        Clear_Record  *menux = new Clear_Record(this);
        menux->show();

    });
//    //臭氧设置
//    connect(btnlist_ui.at(2),&QPushButton::clicked,[=](){
////        Seto3_Menu  *menux = new Seto3_Menu(this);
////        menux->show();
//    });


    //返回
    connect(btnlist_ui.at(2),&QPushButton::clicked,[=](){
        this->parentWidget()->show();
        this->close();
    });
}
bool dataRecord_Menu::eventFilter(QObject *watched, QEvent *event)
{

//            key_Event::key_Event1(pos,watched, event, btnlist, btnlist_ui);
        for(int i=0;i<btnlist_ui.length();i++)
            if(btnlist_ui.at(i) == watched)
        {
            if(event->type() == QEvent::KeyPress)
            {
               QKeyEvent *ev = (QKeyEvent *)event;
               QPushButton *button = (QPushButton *)watched;
               switch (ev->key())
               {
               case OK:
                 {
                   emit  button->clicked();
                   break;
                 }
               case UP://上
               {
                   if(focusWidget() != btnlist_ui.first())
                   focusPreviousChild();
                   focusPreviousChild();
                   focusPreviousChild();
                   focusPreviousChild();
                   break;
               }
               case DOWN://下
               {
                   if(focusWidget() != btnlist_ui.back())
                   focusNextChild();
                   focusNextChild();
                   focusNextChild();
                   focusNextChild();
                   break;
               }
               case LEFT://左
               {
                 if(focusWidget() != btnlist_ui.first())
                      focusPreviousChild();
                 break;
               }
               case RIGHT://右
               {
                 if(focusWidget() != btnlist_ui.back())
                      focusNextChild();
              break;
               }
               case BACK:
               {
                   this->parentWidget()->show();
                   this->close();
                   break;
               }
               case INIT:
               {

                   init_Show *show = new init_Show(this);
                   show->show();
                   this->hide();
                   break;
               }
               default:
                   break;
               }
            }
            else if (event->type()==QEvent::FocusIn)     //然后再判断控件的具体事件 (这里指获得焦点事件)
                      {
                          QPushButton *focus_button = (QPushButton *)watched;
                                  focus_button->setFixedSize(160,120);
//                                  focus_button->setStyleSheet(focusBtn[2]->styleSheet());
//                                  focus_button->setIconSize(QSize(1,2));
                      }
            else if (event->type()==QEvent::FocusOut)    // 这里指 控件的失去焦点事件
                     {
                QPushButton *focus_button = (QPushButton *)watched;
                        focus_button->setFixedSize(120,90);
                     }
            }
        return QWidget::eventFilter(watched,event);//返回父类的事件过滤器

}

